// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

//#undef check
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Camera/CameraComponent.h"
#include "Components/SceneCaptureComponent2D.h"
#include "Engine/TextureRenderTarget2D.h"
#include "ScreenCapturer.generated.h"

UCLASS()
class EXAMPLE10_UE4_API AScreenCapturer : public AActor
{
	GENERATED_BODY()
	
public:
	AScreenCapturer();

	UPROPERTY(EditAnywhere, Category = "ScreenCapture",
		      meta = (ClampMin = "32", ClampMax = "4096", UIMin = "32", UIMax = "4096"))
	uint32 _resolution;

	UPROPERTY(EditAnywhere, Category = "ScreenCapture",
		      meta = (ClampMin = "20.0", ClampMax = "179.0", UIMin = "20.0", UIMax = "179.0"))
	float _fieldOfView;

	UPROPERTY(EditAnywhere, Category = "ScreenCapture")
	FString _outputFilePath;

protected:
	virtual void BeginPlay() override;
	virtual void EndPlay(const EEndPlayReason::Type reason) override;

	UTextureRenderTarget2D* _renderTarget;
	USceneCaptureComponent2D* _sceneCapture;
	UCameraComponent* _captureCamera;
	cv::VideoWriter _writer;

public:
	virtual void Tick(float DeltaTime) override;
};
